<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <input type="text">
    <button>提交</button>
    <div></div>
</body>
<script>
    var input = document.querySelector('input')
    var button = document.querySelector('button')
    var div = document.querySelector('div')

    var socket = new WebSocket('ws://10.25.93.169:3001')

    socket.addEventListener('open', function (event) {
        socket.send('连接成功');
        console.log('event', event)
        // alert('连接成功')
    });
    button.addEventListener('click', () => {
        socket.send(input.value)
        input.value = ''
    })
    // Listen for messages   "miniprogramRoot": "unpackage/dist/dev/mp-weixin/",
    socket.addEventListener('message', function (event) {
        console.log('Message from server ', event.data);
        let dv = document.createElement('div')
        dv.innerHTML = event.data
        div.append(dv)
    });
</script>

</html>